<?php
// +----------------------------------------------------------------------
// | 小说系统---文案管理 [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------

namespace app\admin\controller;
use app\common\controller\Admin;

class Batch extends Admin {

    /**
      * lastchapter [更新最后章节]
      *
      * @return type
    **/
	public function lastchapter() {
		if(IS_POST){
			$novel=db('novel')->where('status=1')->column('id');
			foreach($novel as $k=>$v){
				$chapter = db('chapter')->where('chaptertype=0 and articleid='.$v)->order('chapterorder DESC')->field('id,articleid,chaptername')->find();

				db('novel')->where('id',$v)->update(['lastvolume' => $chapter['chaptername'],'lastvolumeid'=>$chapter['id']]);
			}  
			return $this->success("操作成功！");
		}
		$this->setMeta("批量更新书籍最后章节");
		return $this->fetch();
	}

	public function batchsize() {
		if(IS_POST){
			$novel=db('novel')->where('status=1')->column('id');
			foreach($novel as $k=>$v){
				$chaptersize = db('chapter')->where('chaptertype=0 and articleid='.$v)->sum('size');
				//var_dump($chaptersize);exit();
				db('novel')->where('id',$v)->update(['size' =>$chaptersize]);
			}
			return $this->success("操作成功！");
		}
		$this->setMeta("批量更新书籍字数");
		return $this->fetch();
		
	}
}